#include <string>
#include <fstream>
#include <vector>

struct transf;
struct node;
class aut;

struct transf
{
    unsigned c;
    unsigned target;

    transf(unsigned ch, unsigned t):
    c(ch), target(t)
    {

    }

    transf():
    c(0), target(0)
    {

    }
};

struct node
{
    bool terminal;
    std::vector<transf> next;

    node():
    terminal(false), next(0)
    {
             
    }
};

class aut
{
    unsigned n_, alph_size_;
    char f_, l_;
    node * nodes_;
    unsigned char_number_(char);
public:
    aut(char, char);
    friend std::ifstream& operator >> (std::ifstream&, aut&);
    std::string check(std::string&);
};

unsigned aut::char_number_(char c)
{
    return c - f_;
}

aut::aut(char f, char l):
f_(f), l_(l), alph_size_(l - f + 1)
{
    
}

std::ifstream& operator >> (std::ifstream& in, aut& a)
{
    unsigned n, m, k, b, d;
    char c;
    in >> n >> m >> k;
    a.n_ = n;
    a.nodes_ = new node[n + 1];
    for (unsigned i = 0; i < k; ++i)
    {
        in >> d;
        a.nodes_[d].terminal = true;
    }
    for (unsigned i = 0; i < m; ++i)
    {
        in >> b >> d >> c;
        a.nodes_[b].next.push_back(transf(a.char_number_(c), d));
    }
    return in;
}

std::string aut::check(std::string& s)
{
    node * * queue = new node * [n_], * * nq = new node * [n_];
    bool * added = new bool[n_ + 1];
    memset(added, 0, (n_ + 1) * sizeof(bool));
    unsigned vcount(1), nv(0);
    queue[0] = nodes_ + 1;
    for (unsigned l = s.length(), i(0); i < l; ++i)
    {
        unsigned c = char_number_(s[i]);
        for (unsigned j = 0; j < vcount; ++j)
        {
            for (unsigned k = 0; k < queue[j]->next.size(); ++k)
            {
                if (c == queue[j]->next[k].c && !added[queue[j]->next[k].target])
                {
                    added[queue[j]->next[k].target] = true;
                    nq[nv] = nodes_ + queue[j]->next[k].target;
                    ++nv;
                }
            }
        }
        memcpy(queue, nq, n_ * sizeof(node *));
        memset(added, 0, (n_ + 1) * sizeof(bool));
        vcount = nv;
        nv = 0;
    }
    std::string ans;
    for (unsigned i = 0; i < vcount; ++i)
    {
        if (queue[i]->terminal)
        {
            ans = "Accepts";
        }
    }
    if (ans.length() == 0)
    {
        ans = "Rejects";
    }
    delete[] added;
    delete[] queue;
    delete[] nq;
    return ans;
}

int main()
{
    std::string s;
    std::ifstream in("problem2.in");
    std::ofstream out("problem2.out");
    aut a('a', 'z');
    in >> s;
    in >> a;
    out << a.check(s);
    return 0;
}